Skip to content

Added a reference to private aliases #7384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

javiereguiluz
Copy link
Member

This fixes #5138.

If I'm right, you can only create private aliases with PHP code, so there's no need to update the other config formats.

use Symfony\Component\DependencyInjection\Definition;

$container->setDefinition('app.phpmailer', new Definition(PhpMailer::class));

$containerBuilder->setAlias('app.mailer', 'app.phpmailer');

// private aliases are created passing 'false' to Alias() second argument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[...] as the second argument

@ogizanagi
Copy link
Contributor

ogizanagi commented Jan 18, 2017

If I'm right, you can only create private aliases with PHP code, so there's no need to update the other config formats.

Aliases can be private by using other formats too, the same way as for classic services definitions:

services:
    app.mailer:
         alias: app.phpmailer
         public: false
<service id="app.mailer" alias="app.phpmailer" public="false" />

use Symfony\Component\DependencyInjection\Definition;

$container->setDefinition('app.phpmailer', new Definition(PhpMailer::class));

$containerBuilder->setAlias('app.mailer', 'app.phpmailer');

// private aliases are created passing 'false' to Alias() second argument
$containerBuilder->setAlias('app.mailer', new Alias('app.phpmailer', false));

This means that when using the container directly, you can access the
Copy link
Contributor

@ogizanagi ogizanagi Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this explanation, I wonder if the above place is the right place to show this? (the alias won't be usable using $container->get(...) when private)

@wouterj
Copy link
Member

wouterj commented Apr 15, 2017

Can we please update this PR to add the other formats as well and include it at the end of the section instead? To avoid confusion as we're talking about "fetching it directly from the container" directly after it atm?

@javiereguiluz
Copy link
Member Author

I'm closing this because I don't know how to finish it. But I leave the related issue open in case somebody wants to fix it. Thanks!

@javiereguiluz javiereguiluz deleted the fix_5138 branch May 24, 2018 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants